/**
 * @BelongsProject : LeetCode
 * @Author : WXY
 * @CreateTime : 2022-12-04  22:32
 * @Description : 反转链表
 * @Version : 1.0
 */

public class Num06_reversePrint {
    public  class ListNode {
      int val;
      ListNode next;
      ListNode(int x) { val = x; }
  }
    public static int[] reversePrint(ListNode head) {
        ListNode pre = null;
        ListNode next = null;
        int count = 0;
        while (head != null) {
            count++;
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }
        int[] arr = new int[count];
        int i = 0;
        while (pre != null) {
            arr[i++] = pre.val;
            pre = pre.next;
        }
        return arr;
    }


}
